package uit.comstore.controller;

import java.util.Date;
import java.util.List;

import uit.comstore.model.blo.CustomerBLO;
import uit.comstore.model.entity.Customer;

public class CustomerAction {
	private CustomerBLO customerBLO;
	private Customer customer;
	private List<Customer> customerList;
	private Long id;
	private String gender;

	public CustomerAction() {
		customerBLO = new CustomerBLO();
	} 

	public String execute(){
		this.customerList = customerBLO.list();
		return "success";
	}

	public String add(){
		try{
			Customer customer = getCustomer();
			customer.setDeleted(0);
			customer.setGender(getGender());
			customer.setDateCreated(new Date());
			customer.setLastModified(new Date());
			customerBLO.add(customer);
		}catch(Exception ex){
			//System.out.println("Cannot add Customer!");
		}
		return "success";
	}

	public String delete() {
		customerBLO.delete(getId());
		return "success";
	}

	public String edit() {
		try{
			Customer customer = getCustomer();
			customer.setGender(getGender());
			customerBLO.update(customer);
		}catch(Exception ex){
			//System.out.println("Cannot add Customer!");
		}
		return "success";
	}


	public void setCustomer(Customer customer){
		this.customer = customer;
	}

	public Customer getCustomer(){
		return this.customer;
	}

	public void setCustomerList(List<Customer> customerList){
		this.customerList = customerList;
	}

	public List<Customer> getCustomerList(){
		return this.customerList;
	}

	public void setId(Long id){
		this.id = id;
	}

	public Long getId(){
		return this.id;
	}

	public void setGender(String gender){
		this.gender = gender;
	}

	public String getGender(){
		return this.gender;
	}
}
